/**
 * 
 */
package pagecode.pages;

import javax.faces.component.html.HtmlForm;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import pagecode.PageCodeBase;

import com.ibm.faces.component.html.HtmlGraphicImageEx;
import com.ibm.faces.component.html.HtmlScriptCollector;

/**
 * @author ocortez
 *
 */
public class IIVPPrincipal extends PageCodeBase {

	protected HtmlScriptCollector scriptCollector1;
	protected HtmlForm form1;
	protected HtmlGraphicImageEx imgLogito;
	protected HtmlOutputText lblNombreUsuario;
	protected HtmlOutputText lblFechaPrincipal;
	protected HtmlOutputText lblPerfilUsuario;

	protected HtmlScriptCollector getScriptCollector1() {
		if (scriptCollector1 == null) {
			scriptCollector1 = (HtmlScriptCollector) findComponentInRoot("scriptCollector1");
		}
		return scriptCollector1;
	}

	protected HtmlForm getForm1() {
		if (form1 == null) {
			form1 = (HtmlForm) findComponentInRoot("form1");
		}
		return form1;
	}

	protected HtmlGraphicImageEx getImgLogito() {
		if (imgLogito == null) {
			imgLogito = (HtmlGraphicImageEx) findComponentInRoot("imgLogito");
		}
		return imgLogito;
	}

	protected HtmlOutputText getLblNombreUsuario() {
		if (lblNombreUsuario == null) {
			lblNombreUsuario = (HtmlOutputText) findComponentInRoot("lblNombreUsuario");
		}
		return lblNombreUsuario;
	}

	protected HtmlOutputText getLblFechaPrincipal() {
		if (lblFechaPrincipal == null) {
			lblFechaPrincipal = (HtmlOutputText) findComponentInRoot("lblFechaPrincipal");
		}
		return lblFechaPrincipal;
	}
	
	/*
	protected DynamicMenu dynamicMenu;
	protected HtmlScriptCollector scriptCollector2;
	
    public DynamicMenu getDynamicMenu() {
        if (dynamicMenu == null) {
            dynamicMenu = (DynamicMenu) getFacesContext().getApplication()
                    .createValueBinding("#{dynamicMenu}").getValue(
                            getFacesContext());
        }
        return dynamicMenu;
    }

	public IIVPPrincipal(){
		System.out.println("IIVPPrincipal");
		List<Menu> opcionesMenu = (List<Menu>) this.getSession(true).getAttribute("OPCIONES_MENU");
		 String valida = (String) this.getRequestParam().get("valida");
		 if (valida.equals("true")) {
		     if (opcionesMenu != null) {
		         try {
		             this.getDynamicMenu().CargaMenu(opcionesMenu);
		            
//		             HttpServletResponse response = (HttpServletResponse) this
//		                     .getFacesContext().getExternalContext()
//		                     .getResponse();
//		             response.sendRedirect("./IIVPPrincipal.faces");
		           
		         } catch (Exception e) {
		             e.printStackTrace();
		         }
		     }
		 }
		
		
	}
	public void onPageLoad(FacesContext facescontext){
		System.out.println("IIVPPrincipal-onPageLoad");
		 List<Menu> opcionesMenu = (List<Menu>) this.getSession(true).getAttribute(
         "OPCIONES_MENU");
		 String valida = (String) this.getRequestParam().get("valida");
		 if (valida == null) {
		     if (opcionesMenu != null) {
		         try {
		             this.getDynamicMenu().CargaMenu(opcionesMenu);
		           
//		             HttpServletResponse response = (HttpServletResponse) this
//		                     .getFacesContext().getExternalContext()
//		                     .getResponse();
//		             response.sendRedirect("./IIVPPrincipal.faces");
		             
		         } catch (Exception e) {
		             e.printStackTrace();
		         }
		     }
		 }
		
		
	}

	
	protected HtmlScriptCollector getScriptCollector2() {
		if (scriptCollector2 == null) {
			scriptCollector2 = (HtmlScriptCollector) findComponentInRoot("scriptCollector2");
		}
		return scriptCollector2;
	}
	*/
	
	public String cerrarSession(){
		//FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		FacesContext fc = FacesContext.getCurrentInstance();
		HttpSession s = (HttpSession) fc.getExternalContext().getSession(false);
		s.invalidate();
		return"login";
	}

	protected HtmlOutputText getLblPerfilUsuario() {
		if (lblPerfilUsuario == null) {
			lblPerfilUsuario = (HtmlOutputText) findComponentInRoot("lblPerfilUsuario");
		}
		return lblPerfilUsuario;
	}
}